<meta charset="utf-8" />
<div class="breadcrumbs" id="breadcrumbs">
	<ul class="breadcrumb">
		<li><i class="ace-icon fa fa-home home-icon"></i> <a href="index">主页</a>
		</li>

		<li><span>预投需求管理</span></li>
	</ul>
	<!-- /.breadcrumb -->
</div>

<script type="text/javascript">
//重置查询
function chongZhi(){
	var a = "";
	$.post("ytxqgl/save",{"xqdh":a},function(){
		pageChange(1);
	});
}

					/* 填充表格 */
function trList(data) {
	
	var dataStr = "";
		$.each(data,function(i, a) {
			  $.each(a.ytxqd.list,function(i, v) { //v. _ rscjh表数据   a.paginate.list -->v
				dataStr += '<tr>';
                dataStr += '<td class="hidden-20"><input name="checkboxs1"  id="checkboxs1" class="ace" type="checkbox" value="'+v.id+'"/> <span class="lbl"></span></td>'; 
	            dataStr += '<td>'+v.xqdh+'</td>';
	            dataStr += '<td>'+v.OAdh+'</td>';
	            dataStr += '<td>'+v.yttzdh+'</td>';
	            dataStr += '<td>'+v.gcdm+'</td>';
	            dataStr += '<td>'+v.jhmc+'</td>';
	            dataStr += '<td>'+v.lrrq+'</td>';
	            dataStr += '<td>'+v.wcrq+'</td>';
	            dataStr += '<td>'+v.xqr+'</td>';
	            dataStr += '<td>'+v.ckwd+'</td>';
	            dataStr += '<td>'+v.scshzt+'</td>';
	            dataStr += '<td>'+v.zt+'</td>';
	            dataStr += '<td>'+v.bz+'</td>';
	            dataStr += '<td><div class="hidden-sm hidden-xs action-buttons">  ';
	    		dataStr += '<a href="javascript:updateUserA('+v.id+',\''+v.jhmc+'\',\''+v.wcrq+'\',\''+v.zt+'\',\''+v.bz+'\')"';
				dataStr += ' class="green "><i class="ace-icon fa fa-pencil bigger-130"></i> </a> <a href="javascript:deleteU('+v.id+')" class="red"> <i class="ace-icon fa fa-trash-o bigger-130"></i> </a></div> </td></tr>';
	        });
	    
	});
	// 把拼接好的表格内容填充到指定位置
	$("#tbody_1").html(dataStr);

}
  $("#submi").click(function(){
				$.post("ytxqgl/save",$("#main").serialize(),function(data){
				pageChange(1);});
					});

function trPost(data){
			if(data.totalPage!=1){
				$("#laypage_3").addClass("hide");
				$("#get_pagination3").removeClass("hide");
				laypage({
				cont : $('#get_pagination3'), //容器。值支持id名、原生dom对象，jquery对象,
				pages : data.totalPage, //总页数
				skip : true, //是否开启跳页
				skin : '#2283C5',//保持ace中间的样式
				first: 1,
				last : data.totalPage, //总页数，将尾页显示为总页数
				curr : data.pageNumber,//当前页
				groups : 5, //连续显示分页数
				jump : function(obj, first) {
					if (!first) { //一定要加此判断，否则初始时会无限刷新
						pageChange(obj.curr);
					}
					}
				});
			}else{
				$("#get_pagination3").addClass("hide");
				$("#laypage_3").removeClass("hide");
			}
			
			
	}

function pageChange(curr) {
	$.get("ytxqgl/save", {"pageNumber": curr}, function(data) {
		trList(data); //调用上面trList()方法，填充表格数据
		trPost(data[0].ytxqd);
		laypage({
		    cont: $('#pages'), //容器。值支持id名、原生dom对象，jquery对象,
		    pages: data[0].ytxqd.totalPage, //总页数
		    skip: true, //是否开启跳页
		    skin: 'molv',//设置信息流模式样式
		    last:  data[0].ytxqd.totalPage, //总页数，将尾页显示为总页数
		    curr: data[0].ytxqd.pageNumber,//当前页
		    groups: 3, //连续显示分页数
		    jump: function(obj, first) {
			if(!first){ //一定要加此判断，否则初始时会无限刷新
				pageChange(obj.curr);
			}
			
		    }
		});
		
		
	});
}

function deleteU(id){
	
	layer.confirm('是否确定删除？', {btn : [ '确定', '取消' ]}, function() {
		$.post("ytxqgl/delete1",{"id":id}, function() {
			layer.msg("已删除");
			pageChange(1);
		});
	}, function() {
		layer.msg("已取消");
	});
}

pageChange(1);

/*复选框js_全选  */
$('table th input:checkbox').on('click',
			function() { 
				var that = this;
				$(this).closest('table').find(
						'tr > td:first-child input:checkbox').each(function() {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
});

/* 入库操作 */
function RK() {

		var ls = $("input[type=checkbox]:checked").size(); //选中的个数
		if (ls != "") {

			layer.confirm('确定入库？', {
				btn : [ '确认', '取消' ]
			//按钮
			}, function() {
				var idlist = '';
				$("input[type='checkbox'][name='checkboxs1']").filter(
						':checked').each(function() {
					idlist = idlist + $(this).val() + ",";
				});
				if (idlist.length > 0) {
					idlist = idlist.substring(0, idlist.length - 1);
					$.post("ytxqgl/add", {
						"idlist" : idlist,
					}, function(data) {
						if (data == "success") {
							pageChange(1);
							layer.closeAll('dialog');//关闭所有弹窗
							idlist = '';
						} else {
							layer.alert("请合理操作！");
							layer.closeAll('dialog');//关闭所有弹窗
						}
					});
				}
				layer.colse();
			}, function() {

			});
		} else {
			layer.alert("请合理操作！");
		}
	}

/* 新增 */
function add() {
	
	window.location.href='/mes/#ytxqgl/Ytglz.html';
/* 	document.getElementById("pform").reset();
	$('#add').removeClass("hide");
	userModel = layer.open({
		type : 1,
		shade : [ 0.5 ],
		title : '新增', //不显示标题
		area : [ '40%', '50%' ], //显示空间
		content : $('#add'), //捕获的元素
		btn : [ '添加', '取消' ],
		yes : function(index, layero) { //或者使用btn1
		
		$.post("ytxqgl/add", $("#pform").serialize(), function() {
			layer.close(index);
				$('#add').addClass("hide");
				pageChange(1);
				layer.msg("添加成功");
			//document.getElementById("pform").submit();
		});
	},
	cancel : function(index) {
		layer.close(index);
		$('#add').addClass("hide"); //取消继续隐藏
		layer.msg("已取消");
	},
}); */
}







</script>


<!-- 更改每页显示数据的数目 -->
<script type="text/javascript">
	var sel=document.getElementById("sel");
sel.onchange=function(){
/* alert(sel.options[sel.selectedIndex].value); */
		$.post("wgrk/fanye", {"infNumber" :sel.options[sel.selectedIndex].value}, function(data) {
			pageChange(1);							
		});
}
</script>

<!-- 修改tab -->
<script type="text/javascript">
	function updateUserA(id,jhmc,wcrq,zt,bz) {
		document.getElementById("uupa").reset();
		$("#id").val(id);
		$("#jhmc").val(jhmc);
		$("#wcrq").val(wcrq);
		$("#zt").val(zt);
		$("#bz").val(bz);
		$('#upa').removeClass("hidden");
		userMode = layer.open({
			type : 1,
			shade : [ 0.5 ],
			title : '修改', //不显示标题
			area : [ '25%', '300px' ], //显示空间
			content : $('#upa'), //捕获的元素
			btn : [ '保存', '取消' ],
			yes : function(index, layero) { //或者使用btn1
				//alert("测试");
				$.post("ytxqgl/updatea", $("#uupa").serialize(), function(
						data) {
					layer.close(index);
					$('#upa').addClass("hidden");
					pageChange(1);	
				});
			},
			cancel : function(index) {
				layer.close(index);
				$('#upa').addClass("hidden"); //取消继续隐藏
			},
		});
	};
	
</script>


<div class="page-content">

         <div class="row">
		  <div class="col-xs-12">

     <div class="tab-content">
		<!-- 不同的内容 -->
		  <div class="tab-pane active" id="tab1">
		  
		  <div class="row">
		  <div class="col-xs-12">
		   <div class="clearfix"></div>
			<div class="table-header">预投需求</div>

			<!-- div.table-responsive -->

			<!-- div.dataTables_borderWrap -->
			<div>
				<div id="dynamic-table_wrapper"
					class="dataTables_wrapper form-inline no-footer">
					 <form method="post" action="ytxqgl/save" id="main">
						<div class="row">
							<div class="col-xs-12">
								需求单号:<input type="text" placeholder="输入需求单号" class="form-control" name="xqdh" />
								计划名称:<input type="text" placeholder="输入计划名称" class="form-control" name="jhm" /> 
								需求人:<input type="text" placeholder="输入需求人" class="form-control" name="xqr" />
								完成日期：<input type="text" onClick="WdatePicker()" style="width:120px;height:30px " ; class="form-control" name="endtime" id="zzsj" />
								<a class="btn btn-sm btn-primary" id="submi2">查询</a>
								<input type="reset" class="btn btn-sm btn-primary" onclick="javascript:chongZhi2()" value="重置">
							  <div class="pull-right">
								<a class="btn btn-sm btn-primary" href="javascript:add()">新增</a>
							  </div>
							</div>
							
						</div>
					</form>
					
					<table
						class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable"	role="grid">
                		<thead>
							<tr role="row">
							    <th class="center" style="width:9px; "><label> <input type="checkbox"class="ace" /> <span class="lbl"></span></label></th>
							    <th>需求单号</th>
								<th>OA需求单号</th>
								<th>预投通知单号</th>
								<th>工厂代码</th>
								<th>计划名称</th>
								<th>录入日期</th>
								<th>完成日期</th>
								<th>需求人</th>
								<th>参考文档</th>
								<th>生产审核状态</th>
								<th>状态</th>
								<th>备注</th>
								<th width="120">操作</th>
							</tr>
						</thead>
						<tbody id="tbody_1">

						</tbody>

					</table>

					<div class="row">
						<div class="col-xs-12">

							<div class="dataTables_paginate paging_simple_numbers  pull-left">
								<label>显示<select name="dynamic-table_length"
									aria-controls="dynamic-table" class="form-control input-sm"  id="sel">
									    <option value="10">10</option>
										<option value="20">20</option>
										<option value="50">50</option>
										<option value="100">100</option>
								</select> 条记录</label>
								</div>
								<div class="dataTables_paginate paging_simple_numbers">
										<ul class="pagination" id="get_pagination3">
										</ul>
										<div class="laypage_main laypageskin_molv" id="laypage_3">
											<span class="laypage_curr" style="background-color:#2283C5">1</span><span
												class="laypage_total"><label>到第</label><input max="1"
												min="1" class="laypage_skip" type="number"><label>页</label>
												<button type="button" class="laypage_btn">
													确定
													</button>
											</span>
										</div>
									</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		</div>
		</div>
		
		
		
		
		
<!-- 修改 -->
<div class="hidden" id="upa">
	<div class="col-xs-1"></div>
	<div class="col-xs-9">
		<form id="uupa"  action="" method="post">
			<input type="hidden" name="s.id" id="id">
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">计划名称</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="s.jhmc" id="jhmc"
						value=""/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">完成日期</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="s.wcrq"
						placeholder="必填" id="wcrq" onClick="WdatePicker()"value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">状态</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="s.zt" id="zt"
						value="" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-4 control-label no-padding-right"
					for="form-field-1">备注</label>
				<div class="col-sm-8" style="float: left">
					<input type="text" class="form-control" name="s.bz"
						id="bz" value="" />
				</div>
			</div>
		</form>
	</div>
	<div class="col-xs-2"></div>
</div>

	<!-- 第一个tab结束 -->
		
</div>
</div>
</div>









<script type="text/javascript">
	jQuery(function($) {
		$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
			_title : function(title) {
				var $title = this.options.title || '&nbsp;';
				if (("title_html" in this.options)
						&& this.options.title_html == true)
					title.html($title);
				else
					title.text($title);
			}
		}));

		//initiate dataTables plugin						初始化表格插件
		/* var oTable1 = $('#dynamic-table')
		//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
		.dataTable({
			bAutoWidth : false,
			"aoColumns" : [ null, null, null, null, null, null, {
				"bSortable" : false
			} ],
			"aaSorting" : [],

		}); */
		//oTable1.fnAdjustColumnSizing();
		//TableTools settings
		TableTools.classes.container = "btn-group btn-overlap";
		TableTools.classes.print = {
			"body" : "DTTT_Print",
			"info" : "tableTools-alert gritter-item-wrapper gritter-info gritter-center white",
			"message" : "tableTools-print-navbar"
		};

		//initiate TableTools extension
		var tableTools_obj = new $.fn.dataTable.TableTools(
				oTable1,
				{
					"sSwfPath" : "plugins/ace/assets/js/dataTables/extensions/TableTools/swf/copy_csv_xls_pdf.swf", //in Ace demo plugins/ace/assets will be replaced by correct assets path

					"sRowSelector" : "td:not(:last-child)",
					"sRowSelect" : "multi",
					"fnRowSelected" : function(row) {
						//check checkbox when row is selected
						try {
							$(row).find('input[type=checkbox]').get(0).checked = true
						} catch (e) {
						}
					},
					"fnRowDeselected" : function(row) {
						//uncheck checkbox
						try {
							$(row).find('input[type=checkbox]').get(0).checked = false
						} catch (e) {
						}
					},

					"sSelectedClass" : "success",
					"aButtons" : [
							{
								"sExtends" : "copy",
								"sToolTip" : "复制到剪贴板",
								"sButtonClass" : "btn btn-white btn-primary btn-bold",
								"sButtonText" : "<i class='fa fa-copy bigger-110 pink'></i>",
								"fnComplete" : function() {
									this.fnInfo(
											'<h3 class="no-margin-top smaller">表格已复制</h3>\
							<p>已复制 '
													+ (oTable1.fnSettings()
															.fnRecordsTotal())
													+ ' 行数据到剪贴板.</p>', 1500);
								}
							},

							{
								"sExtends" : "csv",
								"sToolTip" : "导出成 CSV",
								"sButtonClass" : "btn btn-white btn-primary  btn-bold",
								"sButtonText" : "<i class='fa fa-file-excel-o bigger-110 green'></i>"
							},

							{
								"sExtends" : "pdf",
								"sToolTip" : "导出成 PDF",
								"sButtonClass" : "btn btn-white btn-primary  btn-bold",
								"sButtonText" : "<i class='fa fa-file-pdf-o bigger-110 red'></i>"
							},

							{
								"sExtends" : "print",
								"sToolTip" : "打印页面",
								"sButtonClass" : "btn btn-white btn-primary  btn-bold",
								"sButtonText" : "<i class='fa fa-print bigger-110 grey'></i>",

								"sMessage" : "<div class='navbar navbar-default'><div class='navbar-header pull-left'><a class='navbar-brand' href='#'><small>可选导航栏 &amp; 文本</small></a></div></div>",

								"sInfo" : "<h3 class='no-margin-top'>打印页面</h3>\
							  <p>请用您的浏览器打印功能打印这个表格 \
							  <br />请打印完成关闭此页面</p>",
							} ]
				});

		//we put a container before our table and append TableTools element to it
		$(tableTools_obj.fnContainer()).appendTo($('.tableTools-container'));

		//also add tooltips to table tools buttons
		//addding tooltips directly to "A" buttons results in buttons disappearing (weired! don't know why!)
		//so we add tooltips to the "DIV" child after it becomes inserted
		//flash objects inside table tools buttons are inserted with some delay (100ms) (for some reason)
		setTimeout(function() {
			$(tableTools_obj.fnContainer()).find('a.DTTT_button').each(
					function() {
						var div = $(this).find('> div');
						if (div.length > 0)
							div.tooltip({
								container : 'body'
							});
						else
							$(this).tooltip({
								container : 'body'
							});
					});
		}, 200);

		//ColVis extension
		var colvis = new $.fn.dataTable.ColVis(oTable1, {
			"buttonText" : "<i class='fa fa-search'></i>",
			"aiExclude" : [ 0, 6 ],
			"bShowAll" : true,
			//"bRestore": true,
			"sAlign" : "right",
			"fnLabel" : function(i, title, th) {
				return $(th).text();//remove icons, etc
			}

		});

		//style it
		$(colvis.button()).addClass('btn-group').find('button').addClass(
				'btn btn-white btn-info btn-bold')

		//and append it to our table tools btn-group, also add tooltip
		$(colvis.button()).prependTo('.tableTools-container .btn-group').attr(
				'title', '显示/隐藏 数据列').tooltip({
			container : 'body'
		});

		//and make the list, buttons and checkboxed Ace-like
		$(colvis.dom.collection)
				.addClass(
						'dropdown-menu dropdown-light dropdown-caret dropdown-caret-right')
				.find('li').wrapInner('<a href="javascript:void(0)" />') //'A' tag is required for better styling
				.find('input[type=checkbox]').addClass('ace').next().addClass(
						'lbl padding-8');

		//table checkboxes
		$('th input[type=checkbox], td input[type=checkbox]').prop('checked',
				false);

		//select/deselect all rows according to table header checkbox
		$('#dynamic-table > thead > tr > th input[type=checkbox]').eq(0).on(
				'click',
				function() {
					var th_checked = this.checked;//checkbox inside "TH" table header

					$(this).closest('table').find('tbody > tr').each(
							function() {
								var row = this;
								if (th_checked)
									tableTools_obj.fnSelect(row);
								else
									tableTools_obj.fnDeselect(row);
							});
				});

		//select/deselect a row when the checkbox is checked/unchecked
		$('#dynamic-table').on('click', 'td input[type=checkbox]', function() {
			var row = $(this).closest('tr').get(0);
			if (!this.checked)
				tableTools_obj.fnSelect(row);
			else
				tableTools_obj.fnDeselect($(this).closest('tr').get(0));
		});

		$(document).on('click', '#dynamic-table .dropdown-toggle', function(e) {
			e.stopImmediatePropagation();
			e.stopPropagation();
			e.preventDefault();
		});

		//And for the first simple table, which doesn't have TableTools or dataTables
		//select/deselect all rows according to table header checkbox
		var active_class = 'active';
		$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on(
				'click',
				function() {
					var th_checked = this.checked;//checkbox inside "TH" table header

					$(this).closest('table').find('tbody > tr').each(
							function() {
								var row = this;
								if (th_checked)
									$(row).addClass(active_class).find(
											'input[type=checkbox]').eq(0).prop(
											'checked', true);
								else
									$(row).removeClass(active_class).find(
											'input[type=checkbox]').eq(0).prop(
											'checked', false);
							});
				});

		//select/deselect a row when the checkbox is checked/unchecked
		$('#simple-table').on('click', 'td input[type=checkbox]', function() {
			var $row = $(this).closest('tr');
			if (this.checked)
				$row.addClass(active_class);
			else
				$row.removeClass(active_class);
		});

		/********************************/
		//add tooltip for small view action buttons in dropdown menu
		$('[data-rel="tooltip"]').tooltip({
			placement : tooltip_placement
		});

		//tooltip placement on right or left
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table');
			var off1 = $parent.offset();
			var w1 = $parent.width();

			var off2 = $source.offset();
			//var w2 = $source.width();

			if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2))
				return 'right';
			return 'left';
		}

	});
</script>